package com.lee9213.conference.track.management.comparator;

import com.lee9213.conference.track.management.entity.TalkEntity;

import java.util.Comparator;

/**
 * 会话排序比较器
 *
 * @author lee9213@163.com
 * @version 1.0
 * @date 2018-07-11 17:06
 */
public final class TalkEntityComparator implements Comparator<TalkEntity> {

    private TalkEntityComparator() {
    }

    private static final class TalkEntityComparatorHolder {
        private static TalkEntityComparator talkEntityComparator = new TalkEntityComparator();
    }

    public static final TalkEntityComparator getInstance() {
        return TalkEntityComparatorHolder.talkEntityComparator;
    }

    @Override
    public int compare(TalkEntity talkEntity1, TalkEntity talkEntity2) {
        if (talkEntity1 == null || talkEntity2 == null) {
            return 0;
        }
        if (talkEntity1.getMinutes() > talkEntity2.getMinutes()) {
            return -1;
        } else if (talkEntity1.getMinutes() < talkEntity2.getMinutes()) {
            return 1;
        }
        return 0;
    }
}
